home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 January: Mac OS SDK / Dev.CD Jan 99 SDK1.toast / Development Kits / Interfaces&Libraries / Universal / Interfaces / CIncludes / OSUtils.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-17  |  10.9 KB  |  438 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        OSUtils.h
  3.  
  4.      Contains:    OS Utilities Interfaces.
  5.  
  6.      Version:    Technology:    Mac OS 8
  7.                  Release:    Universal Interfaces 3.2
  8.  
  9.      Copyright:    © 1985-1998 by Apple Computer, Inc., all rights reserved
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __OSUTILS__
  18. #define __OSUTILS__
  19.  
  20. #ifndef __MACTYPES__
  21. #include <MacTypes.h>
  22. #endif
  23. #ifndef __MIXEDMODE__
  24. #include <MixedMode.h>
  25. #endif
  26. /*  HandToHand and other memory utilties were moved to MacMemory.h */
  27. #ifndef __MACMEMORY__
  28. #include <MacMemory.h>
  29. #endif
  30. /*  GetTrapAddress and other trap table utilties were moved to Patches.h */
  31. #ifndef __PATCHES__
  32. #include <Patches.h>
  33. #endif
  34. /*  Date and Time utilties were moved to DateTimeUtils.h */
  35. #ifndef __DATETIMEUTILS__
  36. #include <DateTimeUtils.h>
  37. #endif
  38. #if !TARGET_OS_MAC
  39. #ifndef __ENDIAN__
  40. #include <Endian.h>
  41. #endif
  42. #endif  /* !TARGET_OS_MAC */
  43.  
  44.  
  45.  
  46. #if PRAGMA_ONCE
  47. #pragma once
  48. #endif
  49.  
  50. #ifdef __cplusplus
  51. extern "C" {
  52. #endif
  53.  
  54. #if PRAGMA_IMPORT
  55. #pragma import on
  56. #endif
  57.  
  58. #if PRAGMA_STRUCT_ALIGN
  59.     #pragma options align=mac68k
  60. #elif PRAGMA_STRUCT_PACKPUSH
  61.     #pragma pack(push, 2)
  62. #elif PRAGMA_STRUCT_PACK
  63.     #pragma pack(2)
  64. #endif
  65.  
  66.  
  67. enum {
  68.     useFree                        = 0,
  69.     useATalk                    = 1,
  70.     useAsync                    = 2,
  71.     useExtClk                    = 3,                            /*Externally clocked*/
  72.     useMIDI                        = 4
  73. };
  74.  
  75.  
  76. enum {
  77.     false32b                    = 0,                            /*24 bit addressing error*/
  78.     true32b                        = 1                                /*32 bit addressing error*/
  79. };
  80.  
  81.  
  82. enum {
  83.                                                                 /* result types for RelString Call */
  84.     sortsBefore                    = -1,                            /*first string < second string*/
  85.     sortsEqual                    = 0,                            /*first string = second string*/
  86.     sortsAfter                    = 1                                /*first string > second string*/
  87. };
  88.  
  89.  
  90. enum {
  91.     dummyType                    = 0,
  92.     vType                        = 1,
  93.     ioQType                        = 2,
  94.     drvQType                    = 3,
  95.     evType                        = 4,
  96.     fsQType                        = 5,
  97.     sIQType                        = 6,
  98.     dtQType                        = 7,
  99.     nmType                        = 8
  100. };
  101.  
  102. typedef SignedByte                         QTypes;
  103.  
  104. struct SysParmType {
  105.     UInt8                             valid;
  106.     UInt8                             aTalkA;
  107.     UInt8                             aTalkB;
  108.     UInt8                             config;
  109.     short                             portA;
  110.     short                             portB;
  111.     long                             alarm;
  112.     short                             font;
  113.     short                             kbdPrint;
  114.     short                             volClik;
  115.     short                             misc;
  116. };
  117. typedef struct SysParmType                SysParmType;
  118.  
  119. typedef SysParmType *                    SysPPtr;
  120.  
  121. struct QElem {
  122.     struct QElem *                    qLink;
  123.     short                             qType;
  124.     short                             qData[1];
  125. };
  126. typedef struct QElem                    QElem;
  127. typedef QElem *                            QElemPtr;
  128. #if TARGET_OS_MAC
  129.  
  130. struct QHdr {
  131.     short                             qFlags;
  132.     QElemPtr                         qHead;
  133.     QElemPtr                         qTail;
  134. };
  135. typedef struct QHdr                        QHdr;
  136. typedef QHdr *                            QHdrPtr;
  137. #else
  138. /*
  139.    QuickTime 3.0:
  140.    this version of QHdr contains the Mutex necessary for
  141.    non-mac non-interrupt code
  142. */
  143.  
  144. struct QHdr {
  145.     short                             qFlags;
  146.     short                             pad;
  147.     long                             MutexID;
  148.     QElemPtr                         qHead;
  149.     QElemPtr                         qTail;
  150. };
  151. typedef struct QHdr                        QHdr;
  152. typedef QHdr *                            QHdrPtr;
  153. #endif  /* TARGET_OS_MAC */
  154.  
  155.  
  156.  
  157. typedef CALLBACK_API( void , DeferredTaskProcPtr )(long dtParam);
  158. /*
  159.     WARNING: DeferredTaskProcPtr uses register based parameters under classic 68k
  160.              and cannot be written in a high-level language without 
  161.              the help of mixed mode or assembly glue.
  162. */
  163. typedef REGISTER_UPP_TYPE(DeferredTaskProcPtr)                     DeferredTaskUPP;
  164. enum { uppDeferredTaskProcInfo = 0x0000B802 };                     /* register no_return_value Func(4_bytes:A1) */
  165. #define NewDeferredTaskProc(userRoutine)                         (DeferredTaskUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppDeferredTaskProcInfo, GetCurrentArchitecture())
  166. #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  167.     #pragma parameter CallDeferredTaskProc(__A0, __A1)
  168.     void CallDeferredTaskProc(DeferredTaskUPP routine, long dtParam) = 0x4E90;
  169. #else
  170.     #define CallDeferredTaskProc(userRoutine, dtParam)             CALL_ONE_PARAMETER_UPP((userRoutine), uppDeferredTaskProcInfo, (dtParam))
  171. #endif
  172.  
  173. struct DeferredTask {
  174.     QElemPtr                         qLink;
  175.     short                             qType;
  176.     short                             dtFlags;
  177.     DeferredTaskUPP                 dtAddr;
  178.     long                             dtParam;
  179.     long                             dtReserved;
  180. };
  181. typedef struct DeferredTask                DeferredTask;
  182. typedef DeferredTask *                    DeferredTaskPtr;
  183. #if TARGET_OS_MAC
  184.  
  185. struct MachineLocation {
  186.     Fract                             latitude;
  187.     Fract                             longitude;
  188.     union {
  189.         SInt8                             dlsDelta;                /* signed byte; daylight savings delta */
  190.         long                             gmtDelta;                /* use low 24-bits only */
  191.     }                                 u;
  192. };
  193. typedef struct MachineLocation            MachineLocation;
  194. #else
  195. /*
  196.     QuickTime 3.0:
  197.     Alignment of MachineLocation is weird. The union above used for delta
  198.     tends not to work on non-Mac compilers.
  199. */
  200.  
  201. struct MachineLocation {
  202.     Fract                             latitude;
  203.     Fract                             longitude;
  204.     BigEndianLong                     delta;                        /* high byte is daylight savings delta, low 24-bits is GMT delta */
  205. };
  206. typedef struct MachineLocation            MachineLocation;
  207. #endif  /* TARGET_OS_MAC */
  208.  
  209. EXTERN_API( Boolean )
  210. IsMetric                        (void)                                                        THREEWORDINLINE(0x3F3C, 0x0004, 0xA9ED);
  211.  
  212. EXTERN_API( SysPPtr )
  213. GetSysPPtr                        (void)                                                        THREEWORDINLINE(0x2EBC, 0x0000, 0x01F8);
  214.  
  215.  
  216. /*
  217.     NOTE: SysBeep() has been moved to Sound.h.  
  218.           We could not automatically #include Sound.h in this file
  219.           because Sound.h indirectly #include's OSUtils.h which
  220.           would make a circular include.
  221. */
  222.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  223.                                                                                             #pragma parameter __D0 DTInstall(__A0)
  224.                                                                                             #endif
  225. EXTERN_API( OSErr )
  226. DTInstall                        (DeferredTaskPtr         dtTaskPtr)                            ONEWORDINLINE(0xA082);
  227.  
  228.  
  229.  
  230. #if TARGET_CPU_PPC || !TARGET_OS_MAC
  231. #define GetMMUMode() ((SInt8)true32b)
  232. #define SwapMMUMode(x) (*(SInt8*)(x) = true32b)
  233. #else
  234. EXTERN_API( SInt8 )
  235. GetMMUMode                        (void)                                                        TWOWORDINLINE(0x1EB8, 0x0CB2);
  236.  
  237.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  238.                                                                                             #pragma parameter SwapMMUMode(__A0)
  239.                                                                                             #endif
  240. EXTERN_API( void )
  241. SwapMMUMode                        (SInt8 *                mode)                                THREEWORDINLINE(0x1010, 0xA05D, 0x1080);
  242.  
  243. #endif
  244.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  245.                                                                                             #pragma parameter Delay(__A0, __A1)
  246.                                                                                             #endif
  247. EXTERN_API( void )
  248. Delay                            (unsigned long             numTicks,
  249.                                  unsigned long *        finalTicks)                            TWOWORDINLINE(0xA03B, 0x2280);
  250.  
  251.  
  252. EXTERN_API( OSErr )
  253. WriteParam                        (void);
  254.  
  255.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  256.                                                                                             #pragma parameter Enqueue(__A0, __A1)
  257.                                                                                             #endif
  258. EXTERN_API( void )
  259. Enqueue                            (QElemPtr                 qElement,
  260.                                  QHdrPtr                 qHeader)                            ONEWORDINLINE(0xA96F);
  261.  
  262.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  263.                                                                                             #pragma parameter __D0 Dequeue(__A0, __A1)
  264.                                                                                             #endif
  265. EXTERN_API( OSErr )
  266. Dequeue                            (QElemPtr                 qElement,
  267.                                  QHdrPtr                 qHeader)                            ONEWORDINLINE(0xA96E);
  268.  
  269.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  270.                                                                                             #pragma parameter __D0 SetCurrentA5
  271.                                                                                             #endif
  272. EXTERN_API( long )
  273. SetCurrentA5                    (void)                                                        THREEWORDINLINE(0x200D, 0x2A78, 0x0904);
  274.  
  275.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  276.                                                                                             #pragma parameter __D0 SetA5(__D0)
  277.                                                                                             #endif
  278. EXTERN_API( long )
  279. SetA5                            (long                     newA5)                                ONEWORDINLINE(0xC18D);
  280.  
  281.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  282.                                                                                             #pragma parameter __D0 InitUtil
  283.                                                                                             #endif
  284. EXTERN_API( OSErr )
  285. InitUtil                        (void)                                                        ONEWORDINLINE(0xA03F);
  286.  
  287.  
  288. #if TARGET_CPU_PPC
  289. EXTERN_API( void )
  290. MakeDataExecutable                (void *                    baseAddress,
  291.                                  unsigned long             length);
  292.  
  293. #endif  /* TARGET_CPU_PPC */
  294.  
  295. #if TARGET_CPU_68K
  296. EXTERN_API( Boolean )
  297. SwapInstructionCache            (Boolean                 cacheEnable);
  298.  
  299. EXTERN_API( void )
  300. FlushInstructionCache            (void)                                                        TWOWORDINLINE(0x7001, 0xA098);
  301.  
  302. EXTERN_API( Boolean )
  303. SwapDataCache                    (Boolean                 cacheEnable);
  304.  
  305. EXTERN_API( void )
  306. FlushDataCache                    (void)                                                        TWOWORDINLINE(0x7003, 0xA098);
  307.  
  308. EXTERN_API( void )
  309. FlushCodeCache                    (void)                                                        ONEWORDINLINE(0xA0BD);
  310.  
  311. #endif  /* TARGET_CPU_68K */
  312.  
  313.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  314.                                                                                             #pragma parameter __D0 FlushCodeCacheRange(__A0, __A1)
  315.                                                                                             #endif
  316. EXTERN_API( OSErr )
  317. FlushCodeCacheRange                (void *                    address,
  318.                                  unsigned long             count)                                TWOWORDINLINE(0x7009, 0xA098);
  319.  
  320.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  321.                                                                                             #pragma parameter ReadLocation(__A0)
  322.                                                                                             #endif
  323. EXTERN_API( void )
  324. ReadLocation                    (MachineLocation *        loc)                                FOURWORDINLINE(0x203C, 0x000C, 0x00E4, 0xA051);
  325.  
  326.  
  327.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  328.                                                                                             #pragma parameter WriteLocation(__A0)
  329.                                                                                             #endif
  330. EXTERN_API( void )
  331. WriteLocation                    (const MachineLocation * loc)                                FOURWORDINLINE(0x203C, 0x000C, 0x00E4, 0xA052);
  332.  
  333.  
  334.  
  335. #if OLDROUTINENAMES
  336. #define IUMetric() IsMetric()
  337. #endif  /* OLDROUTINENAMES */
  338.  
  339. /*
  340.     NOTE: SysEnvirons is obsolete.  You should be using Gestalt.
  341. */
  342. /* Environs Equates */
  343.  
  344. enum {
  345.     curSysEnvVers                = 2                                /*Updated to equal latest SysEnvirons version*/
  346. };
  347.  
  348.  
  349. struct SysEnvRec {
  350.     short                             environsVersion;
  351.     short                             machineType;
  352.     short                             systemVersion;
  353.     short                             processor;
  354.     Boolean                         hasFPU;
  355.     Boolean                         hasColorQD;
  356.     short                             keyBoardType;
  357.     short                             atDrvrVersNum;
  358.     short                             sysVRefNum;
  359. };
  360. typedef struct SysEnvRec                SysEnvRec;
  361.  
  362. enum {
  363.                                                                 /* Machine Types */
  364.     envMac                        = -1,
  365.     envXL                        = -2,
  366.     envMachUnknown                = 0,
  367.     env512KE                    = 1,
  368.     envMacPlus                    = 2,
  369.     envSE                        = 3,
  370.     envMacII                    = 4,
  371.     envMacIIx                    = 5,
  372.     envMacIIcx                    = 6,
  373.     envSE30                        = 7,
  374.     envPortable                    = 8,
  375.     envMacIIci                    = 9,
  376.     envMacIIfx                    = 11
  377. };
  378.  
  379.  
  380. enum {
  381.                                                                 /* CPU types */
  382.     envCPUUnknown                = 0,
  383.     env68000                    = 1,
  384.     env68010                    = 2,
  385.     env68020                    = 3,
  386.     env68030                    = 4,
  387.     env68040                    = 5
  388. };
  389.  
  390.  
  391. enum {
  392.                                                                 /* Keyboard types */
  393.     envUnknownKbd                = 0,
  394.     envMacKbd                    = 1,
  395.     envMacAndPad                = 2,
  396.     envMacPlusKbd                = 3,
  397.     envAExtendKbd                = 4,
  398.     envStandADBKbd                = 5,
  399.     envPrtblADBKbd                = 6,
  400.     envPrtblISOKbd                = 7,
  401.     envStdISOADBKbd                = 8,
  402.     envExtISOADBKbd                = 9
  403. };
  404.  
  405.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  406.                                                                                             #pragma parameter __D0 SysEnvirons(__D0, __A0)
  407.                                                                                             #endif
  408. EXTERN_API( OSErr )
  409. SysEnvirons                        (short                     versionRequested,
  410.                                  SysEnvRec *            theWorld)                            ONEWORDINLINE(0xA090);
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418. #if PRAGMA_STRUCT_ALIGN
  419.     #pragma options align=reset
  420. #elif PRAGMA_STRUCT_PACKPUSH
  421.     #pragma pack(pop)
  422. #elif PRAGMA_STRUCT_PACK
  423.     #pragma pack()
  424. #endif
  425.  
  426. #ifdef PRAGMA_IMPORT_OFF
  427. #pragma import off
  428. #elif PRAGMA_IMPORT
  429. #pragma import reset
  430. #endif
  431.  
  432. #ifdef __cplusplus
  433. }
  434. #endif
  435.  
  436. #endif /* __OSUTILS__ */
  437.  
  438.